// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-11-11

#ifndef __SVR_ASYNCQUEUE_H_COMMON_SVR_BASE__
#define __SVR_ASYNCQUEUE_H_COMMON_SVR_BASE__

#pragma once

#include "svr_asyncobj.h"

namespace JoyServer
{

class CJoyServer;
class CJoyAsyncObject;
class CJoyAsyncExec;

class CJoyAsyncQueue : public CJoyAsyncObject
{
protected:
    friend class CJoyUser;

    CJoyAsyncExec*  m_exec;
    CJoyCriticalSection     m_lock;
    CList<CJoyAsyncObject*> m_objects;
    volatile bool m_finish;
    CJoyAsyncObject* PeekObject();

    virtual void OnExecute();
public:
    CJoyAsyncQueue();
    virtual ~CJoyAsyncQueue();

    bool IsEmpty() const
    {
        return m_objects.IsEmpty()!=0 && m_finish;
    }
    void ClearObjects();
    bool QueueObject(CJoyAsyncObject* asyObj);

    virtual bool Create(CJoyAsyncExec* pExec);
    virtual void Destroy();
};


} // namespace JoyServer

#endif  // __SVR_ASYNCQUEUE_H_COMMON_SVR_BASE__